#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include "html_link.h"
#include "html_tree.h"


#define BUF_SIZE 1<<20
#define DEBUG 0

char html_buf[BUF_SIZE];

int
main(void)
{
	memset(html_buf,0,sizeof(html_buf));
	FILE *fp = fopen("hao123.html","r");
	assert(fp != NULL);
	fread(html_buf,sizeof(char),BUF_SIZE,fp);

	fclose(fp);

	struct Tree_node *root = NULL;


	Create_tree(&root,html_buf);
#if DEBUG

	traversal_to_string(root,0);
#endif

#if DEBUG
	struct linked_list_text_node *ptr = NULL;
	get_text_value_list(root,&ptr);
	while(ptr != NULL)
	{
		puts(ptr->str);
		ptr=ptr->next;
	}
#endif
#if DEBUG
	struct linked_list_tree_node *ptr = NULL;
	get_content_by_tag(root,&ptr,"div");
	assert(ptr != NULL);
	while(ptr != NULL)
	{
		traversal_to_string(get_child(ptr->element),0);
		puts("-----------------------------------------------------------------------------");
		ptr = ptr->next;
	}
#endif

	struct linked_list_attr_node *ptr = NULL;
	get_attr_value_list(root,&ptr,"href");

	assert(ptr != NULL);
	while(ptr != NULL)
	{
		assert(ptr->str != NULL);
		puts(ptr->str);
		ptr= ptr->next;
	}

	free_tree(root);

	return EXIT_SUCCESS;
}
